import { defineConfig } from 'vite'
import { loadEnv } from 'vite';
// import path from 'path';
// const pathSrc = path.resolve(__dirname,'src')
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default ({ command, mode }) => defineConfig({
  plugins: [vue()],
  server: {

    proxy: {
      '/api': {
        target: mode==='development' ? loadEnv(mode, process.cwd()).VITE_APP_DEV_URL:loadEnv(mode, process.cwd()).VITE_APP_PROD_URL,
        changeOrigin: true,  // 允许跨域
        rewrite: path => path.replace(/^\/api/, '')
      }
    }
  }

})
